//== AUTOMATICALLY GENERATED =========================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/lexer/lexcore.h"

#include "sagittarius/io/io.h"

//== BEGINNING OF CODE ===============================================================


#define SM_START_STATE 0
#define DFA_ACC_NONE 0xffffffff
#define STATE_INFO_SHIFT_MASK 0x00000000000000ff
#define STATE_INFO_OFFSET_MASK 0xffffffff00000000


#define SM_ITABLE_CONTINUE_FLAG 0x10000000
#define SM_LOOKUP_MASK 0x0fffffff
#define DFA_INVALID_TRANSITION 0xffff0000





#define TOKEN_ws 0
#define TOKEN_id 1
#define TOKEN_lparen 2
#define TOKEN_rparen 3
#define TOKEN_lbrack 4
#define TOKEN_rbrack 5
#define TOKEN_lbrace 6
#define TOKEN_rbrace 7
#define TOKEN_plus 8
#define TOKEN_dash 9
#define TOKEN_star 10
#define TOKEN_slash 11
#define TOKEN_amp 12
#define TOKEN_comma 13
#define TOKEN_integral 14



uint64 state_info[16] = {
  0x0000000000000000, 0x0000000000000000, 0x0000010000000000, 0x0000020000000000,
  0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
  0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
  0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000};



typedef struct {
    constLexBuf w; /* Position in the input buf */
    constLexBuf strt; /* Starting position of accepted pattern (where ac = true) */
    uint32 s; /* State */
    uint32 ef; /* Error flag */
    uint32 ac; /* Accepted pattern */
} sm_c_parserState;



void dfa_init_ps(sm_c_parserState* ps, constLexBuf buf) {
    /* Initialize the parser state */
    ps->s = 0;
    ps->w = buf;
    ps->strt = ps->w;
    ps->ac = DFA_ACC_NONE;
    ps->ef = 0;
}



const char* identifiers[15] = {
  "ws",
  "id",
  "lparen",
  "rparen",
  "lbrack",
  "rbrack",
  "lbrace",
  "rbrace",
  "plus",
  "dash",
  "star",
  "slash",
  "amp",
  "comma",
  "integral"
};

void dfa_print_acc_id(uint32 ac) {
    sg_writeCStr(1, identifiers[ac]);
}







void init_symbols() {
}



void clear_symbols() {
}



uint32 ttbl[768] = {
  /* Transitions for tier 1, state 0*/
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x10000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x10000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1000000e, 0x00000000,
  0x10000004, 0x10000005, 0x1000000c, 0x1000000a, 0x1000000f, 0x1000000b, 0x00000000, 0x1000000d,
  0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003,
  0x10000003, 0x10000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000006, 0x00000000, 0x10000007, 0x00000000, 0x10000002,
  0x00000000, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000008, 0x00000000, 0x10000009, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  /* Transitions for tier 1, state 2*/
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x10000002,
  0x00000000, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002, 0x10000002,
  0x10000002, 0x10000002, 0x10000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  /* Transitions for tier 1, state 3*/
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003, 0x10000003,
  0x10000003, 0x10000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
};


uint32 lookup_transition(uint32 s, sm_c_parserState* ps) {
    LXAlphaType x;
    LX_FORCE_INIT(x);
    
    uint32 shift=state_info[s] & STATE_INFO_SHIFT_MASK;
    LXFixedType base=(uint32)((state_info[s] & STATE_INFO_OFFSET_MASK) >> 32);
    while(shift) {
        LX_ALPHA_SET(x, *ps->w);
        LX_ALPHA_RSHIFT_SPC(x, (8*shift));
        base = ttbl[base + (LXFixedType)(LX_GET_FIXED_VALUE(x) & 0xff)];
        if(base & SM_ITABLE_CONTINUE_FLAG)
            base = base & SM_LOOKUP_MASK;
        else
            return DFA_INVALID_TRANSITION;
        --shift;
    }
    /* Get next state */
    LX_ALPHA_SET(x, *ps->w);
    base = ttbl[base + (LXFixedType)(LX_GET_FIXED_VALUE(x) & 0xff)];
    
    LX_ALPHA_CLEAR(x);
    
    if(base & SM_ITABLE_CONTINUE_FLAG)
        base = base & SM_LOOKUP_MASK;
    else
        return DFA_INVALID_TRANSITION;
    
    return (uint32)base & SM_LOOKUP_MASK;
}


void resume_dfa(sm_c_parserState* ps) {
    uint32 s;
    
    while(!LX_CMPALPHA_EQ_SPC(*ps->w, '\0') && !ps->ef) {
        switch(ps->s) {
          case 0:
            /* State 0 has transitions: CS{0xa, } -> 1, CS{A-Z,_,a-z} -> 2, CS{0-9} -> 3, CS{(} -> 4, CS{)} -> 5, CS{[} -> 6, CS{]} -> 7, CS{{} -> 8, CS{}} -> 9, CS{+} -> 10, CS{-} -> 11, CS{*} -> 12, CS{/} -> 13, CS{&} -> 14, CS{,} -> 15 */
            s = lookup_transition(ps->s, ps);
            if(s != DFA_INVALID_TRANSITION) {
                ps->s = s;
                ++ps->w;
                break;
            }
            /* Reject if there are no legal transitions */
            ps->ef = 1;
            return;
          case 1:
            /* State 1 has no outbound transitions*/
            /* Accepting state for "ws" */
            /* Accept pattern 0 */
            /* Reset */
            ps->s = 0;
            ps->ac = DFA_ACC_NONE;
            ps->strt = ps->w;
            break;
          case 2:
            /* State 2 has transitions: CS{a-z,_,A-Z,0-9} -> 2 */
            /* Accepting state for "id" */
            s = lookup_transition(ps->s, ps);
            if(s != DFA_INVALID_TRANSITION) {
                ps->s = s;
                ++ps->w;
                break;
            }
            /* Accept pattern 1 */
            ps->ac = 1;
            return;
          case 3:
            /* State 3 has transitions: CS{0-9} -> 3 */
            s = lookup_transition(ps->s, ps);
            if(s != DFA_INVALID_TRANSITION) {
                ps->s = s;
                ++ps->w;
                break;
            }
            /* Reject if there are no legal transitions */
            ps->ef = 1;
            return;
          case 4:
            /* State 4 has no outbound transitions*/
            /* Accepting state for "lparen" */
            /* Accept pattern 2 */
            ps->ac = 2;
            return;
          case 5:
            /* State 5 has no outbound transitions*/
            /* Accepting state for "rparen" */
            /* Accept pattern 3 */
            ps->ac = 3;
            return;
          case 6:
            /* State 6 has no outbound transitions*/
            /* Accepting state for "lbrack" */
            /* Accept pattern 4 */
            ps->ac = 4;
            return;
          case 7:
            /* State 7 has no outbound transitions*/
            /* Accepting state for "rbrack" */
            /* Accept pattern 5 */
            ps->ac = 5;
            return;
          case 8:
            /* State 8 has no outbound transitions*/
            /* Accepting state for "lbrace" */
            /* Accept pattern 6 */
            ps->ac = 6;
            return;
          case 9:
            /* State 9 has no outbound transitions*/
            /* Accepting state for "rbrace" */
            /* Accept pattern 7 */
            ps->ac = 7;
            return;
          case 10:
            /* State 10 has no outbound transitions*/
            /* Accepting state for "plus" */
            /* Accept pattern 8 */
            ps->ac = 8;
            return;
          case 11:
            /* State 11 has no outbound transitions*/
            /* Accepting state for "dash" */
            /* Accept pattern 9 */
            ps->ac = 9;
            return;
          case 12:
            /* State 12 has no outbound transitions*/
            /* Accepting state for "star" */
            /* Accept pattern 10 */
            ps->ac = 10;
            return;
          case 13:
            /* State 13 has no outbound transitions*/
            /* Accepting state for "slash" */
            /* Accept pattern 11 */
            ps->ac = 11;
            return;
          case 14:
            /* State 14 has no outbound transitions*/
            /* Accepting state for "amp" */
            /* Accept pattern 12 */
            ps->ac = 12;
            return;
          case 15:
            /* State 15 has no outbound transitions*/
            /* Accepting state for "comma" */
            /* Accept pattern 13 */
            ps->ac = 13;
            return;
        }
    }
}


